/**
* @author Meng Zhang
**/

#pragma once
#include "../MVC/MVC.h"
#include <set>

class TextBuffer;
class CScintillaCtrl;
class CCineApp;

class TextBufferFactory : public IBufferFactory {
	//DECLARE_SINGLETON(TextBufferFactory)
	friend class BufferController;
	TextBufferFactory();
	~TextBufferFactory();
	virtual BufferBase* CreateBuffer(BufferCreateInfo* bufferCreateInfo = NULL);
	virtual bool DestroyBuffer(BufferBase* buffer);
	virtual BufferListener* CreateView();
	
	//void SetBufferContent(int id , const TCHAR* content , int length);
	void LoadFile(TextBuffer &buffer);
	void SaveFile(TextBuffer &buffer);
	void Destroy();
	bool HaveBuffer(BufferBase* buffer);
	bool EnsureSave(TextBuffer &buffer);
	bool EnsureSaveModify();
	void UpdateBufferSwap(TextBuffer& buffer);
	void RestoreBufferFromSwap(TextBuffer &buffer);
	void ClearBufferSwap(TextBuffer& buffer);
	void VirtualSave(TextBuffer &buffer);
	//property
	const std::set<TextBuffer*>& TextBuffers() const { return textBuffers; }
private:
	void ReleaseBuffer(TextBuffer* buffer);
	CScintillaCtrl* scintillaCtrl;
	TextBuffer* emptyBuffer;
	CCineApp* cine;
	std::set<TextBuffer*> textBuffers;
};
